package vashion.azeroth.api.controller.member;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import vashion.azeroth.api.controller.base.BaseController;
import vashion.azeroth.context.pojo.PersonalFollowContext;
import vashion.azeroth.core.personal.pojo.PersonalFollow;
import vashion.azeroth.core.result.ApiResult;
import vashion.azeroth.core.service.PersonalFollowService;

@Controller
@RequestMapping("/member")
public class FollowController<T> extends BaseController {

	// 增加一个测试注释

	@Autowired
	private PersonalFollowService<T> personalFollowService;

	/**
	 * 关注粉丝
	 * 
	 * */
	@RequestMapping("addFollow.htm")
	@ResponseBody
	public ApiResult<Boolean> addFavorite(
			@ModelAttribute("personalFollow") PersonalFollow personalFollow) {

		ApiResult<Boolean> ApiResult = personalFollowService
				.addFollow(personalFollow);
		return ApiResult;
	}

	/**
	 * 取消关注
	 * 
	 * */

	@RequestMapping("cancelFollow.htm")
	@ResponseBody
	public ApiResult<Boolean> cancelFollow(
			@ModelAttribute("personalFollow") PersonalFollow personalFollow) {

		ApiResult<Boolean> ApiResult = personalFollowService
				.cancelFollow(personalFollow);

		return ApiResult;
	}

	/**
	 * 查询我关注的人
	 * 
	 * */

	@RequestMapping("findFollowdByMe.htm")
	@ResponseBody
	public ApiResult<List<PersonalFollowContext>> findFollowdByMe(
			@ModelAttribute("personalFollow") PersonalFollow personalFollow) {

		Long memberId = personalFollow.getMemberId();

		if (null == memberId) {
			return null;
		}

		int pageNum = personalFollow.getPageNum();

		int pageSize = personalFollow.getPageSize();

		pageNum = (pageNum - 1) < 0 ? 1 : pageNum;

		pageNum = (pageNum - 1) * pageSize;

		ApiResult<List<PersonalFollowContext>> ApiResult = personalFollowService.findFollowdByMe(memberId, pageNum, pageSize);

		return ApiResult;
	}

	/**
	 * 查询关注我的人
	 * 
	 * */

	@RequestMapping("findMyFollow.htm")
	@ResponseBody
	public ApiResult<List<PersonalFollowContext>> findMyFollow(
			@ModelAttribute("personalFollow") PersonalFollow personalFollow) {

		Long memberId = personalFollow.getMemberId();

		if (null == memberId) {
			return null;
		}

		int pageNum = personalFollow.getPageNum();

		int pageSize = personalFollow.getPageSize();

		pageNum = (pageNum - 1) < 0 ? 1 : pageNum;

		pageNum = (pageNum - 1) * pageSize;

		ApiResult<List<PersonalFollowContext>> ApiResult = personalFollowService
				.findMyFollow(memberId, pageNum, pageSize);
		return ApiResult;
	}

	/**
	 * 查询会员关系 是否关注
	 * 
	 * */

	@RequestMapping("isFollow.htm")
	@ResponseBody
	public ApiResult<Integer> isFollow(
			@ModelAttribute("personalFollow") PersonalFollow personalFollow) {

		Long memberId = personalFollow.getMemberId();

		Long fansMemberId = personalFollow.getFansMemberId();

		if (null == memberId || fansMemberId == null) {
			return null;
		}

		ApiResult<Integer> ApiResult = personalFollowService.isFollowed(
				fansMemberId, memberId);
		return ApiResult;
	}

	/**
	 * 添加入黑名单
	 * 
	 * */
	@RequestMapping("followInBlack.htm")
	@ResponseBody
	public ApiResult<Boolean> followInBlackList(
			@ModelAttribute("personalFollow") PersonalFollow personalFollow) {

		ApiResult<Boolean> ApiResult = personalFollowService
				.followInBlackList(personalFollow);

		return ApiResult;

	}

}
